import { ref } from "vue"
import store from "@/store"
import { defineStore } from "pinia"
import { IGetComboSourceData } from "@/api/combo-source/types/combo-source"
import { getComboSourceDataApi } from "@/api/combo-source"
export const useComboSourceStore = defineStore(
  "comboSource",
  () => {
    const comboSourceListStore = ref<IGetComboSourceData[]>([])
    /** 设置套餐来源列表 */
    const setComboSourceList = (value: IGetComboSourceData[]) => {
      comboSourceListStore.value = value
    }
    const getCsourceFn = async () => {
      //套餐来源持久化
      await getComboSourceDataApi({
        page: 1,
        size: 100000
      }).then((res: any) => {
        setComboSourceList(res.data.list)
      })
    }
    return {
      comboSourceListStore,
      setComboSourceList,
      getCsourceFn
    }
  },
  {
    persist: {
      enabled: true,
      strategies: [
        {
          storage: localStorage
          // paths: ["jobListStore", "authListStore"] //指定要长久化的字段
        }
      ]
    }
  }
)
/** 在 setup 外使用 */
export function useComboSourceStoreHook() {
  return useComboSourceStore(store)
}
